<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>-->
    <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
    <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
    <!--[endif]-->
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>

</head>
<body>
<div class="layui-fluid" id="flowDiv" onload="onLoad()">
    <div class="zTreeBackground left" style="float: left;width:300px">
        <div class="titlediv">
            <p style="text-align:right;background-color:white;line-height: 30px">
                专业领域信息<i class="layui-icon layui-icon-refresh" style="margin-left: 36%" onclick="searchByName()"></i>&ensp;&ensp;
            </p>

        </div>
        <div class="searchdiv" >
            <div class="layui-input-inline" style="width:100%">
                <input type="text" id="search" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入名称"/>
                <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="searchByName()"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv" style="overflow:auto">
            <div class="ztreeuldiv">
                <ul id="treeStructure" class="ztree"></ul>
            </div>
        </div>
    </div>
    <div class="zTreeBackground right" style="float: left; padding-left:1%;width:70%">
        <div class="layui-form-item" style="width:99%;margin-bottom:-10px;text-align:right;">
            <div class="layui-inline">
                <label class="layui-form-label">构件名称</label>
                <div class="layui-input-block">
                    <input type="text" id="elementName1" lay-verify="required|phone" autocomplete="off" class="layui-input" placeholder="请输入构件名称"/>
                    <i class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;" onclick="easysearch()"></i>
                </div>
            </div>
            <button type="button" style="margin-left:12px;margin-top: -12px;" class="layui-btn layui-btn-normal" onclick="moresearch()"><i class="layui-icon layui-icon-search"></i>高级搜索</button>
        </div>
        <div class="search_float_div" style="position:absolute;z-index:999;width:70%;background-color: #f1f1f1;padding-top: 20px;text-align:left;display:none">
            <div class="layui-form-item">
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">编码</label>
                    <div class="layui-input-block">
                        <input type="text" id="code" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="name" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline" style="width:400px;">
                    <label class="layui-form-label">分类</label>
                    <div class="layui-input-block">
                        <input type="text" id="classy" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline"  style="width:400px;">
                    <label class="layui-form-label">构件名称</label>
                    <div class="layui-input-block">
                        <input type="text" id="elementName" lay-verify="required|phone" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="searchTable()"><i class="layui-icon layui-icon-search"></i>查询</button>
                    <button type="button" style="float: left;margin-left: 12px" class="layui-btn layui-btn-normal" onclick="resetSearchTable()"><i class="layui-icon layui-icon-search"></i>重置</button>
                    <button type="button" class="layui-btn layui-btn-primary" onclick="canclesearch()">取消</button>
                </div>
            </div>
        </div>
        <table class="layui-hide" id="datatable"></table>
        <script type="text/html" id="toolbar">
        </script>

    </div>

</div>
</body>
<SCRIPT type="text/javascript">
    var zTreeObj,methodid,form,tableObj,table,level=0,treeNodeId=-1,selecNode,count=1;
    $(function(){
        loadbutton("toolbar");//加载按钮loadbutton(id)，id为button容器id，不传默认为buttongroup
        loadTree();
    })
    window.onload = getContentSize;
    window.onresize = getContentSize;

    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理
        $(".search_float_div").css("width",($(document).width()-350)+'px');//自适应表格处理
    }
    /* *
     * @Author bxf
     * @Description 高级搜索
     * @Date 17:34 2019/8/30
     * @param null
     * @return
     */
    function moresearch(){
        $(".search_float_div").slideToggle();
    }
    /**
     * 左侧树设置
     * @type
     */
    var setting = {
        edit:{
            enable: false,
        },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"pid",
                rootPid:-1
            },
            key: {
                isParent:"parent",
            }
        },
        callback: {
            beforeClick: zTreeBeforeClick,
            onClick: zTreeOnClick
        }
    };
    /**
     * @Author bxf
     * @Description 搜索框按钮
     * @Date 11:20 2019/7/17
     * @Param
     * @return
     **/
    function searchByName(){
        loadTree();
    }
    /**
     * @Author bxf
     * @Description 刷新左边树
     * @Date 11:20 2019/7/17
     * @Param
     * @return
     **/
    function refreshRoot(){
        count = 1;
        loadTree();
    }

    /**
     * 点击前验证
     * @param treeId
     * @param treeNode
     * @param clickFlag
     * @returns {boolean}
     */
    function zTreeBeforeClick(treeId, treeNode, clickFlag) {
        //return (treeNode.id !== menuid);
        return true;
    };


    function gettable(){
        var obj = table.checkStatus('datatable');
        alert(obj.data.length);
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行修改！");
            return false;
        }
    }
    function addtable(val){
        var option = '<tr data-index="10" class="">'+
                        '<td data-field="0" data-key="1-0-0" class="layui-table-col-special"><div class="layui-table-cell laytable-cell-1-0-0 laytable-cell-checkbox"><input type="checkbox" name="layTableCheckbox" lay-skin="primary"><div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div></div></td><td data-field="1" data-key="1-0-1" align="center" class="layui-table-col-special"><div class="layui-table-cell laytable-cell-1-0-1 laytable-cell-numbers">1</div></td>'+
                        '<td data-field="code" data-key="1-0-2" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-2">1212122423423</div></td>'+
                        '<td data-field="name" data-key="1-0-3" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-3">12121212</div></td>'+
                        '<td data-field="classy" data-key="1-0-4" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-4">12121</div></td>'+
                        '<td data-field="elementName" data-key="1-0-5" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-5">1212</div></td>'+
                        '<td data-field="indsName" data-key="1-0-6" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-6"></div></td>'+
                        '<td data-field="description" data-key="1-0-7" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-7"></div></td>'+
                        '<td data-field="ebs" data-key="1-0-8" align="center" class=""><div class="layui-table-cell laytable-cell-1-0-8">12121212</div></td></tr>';
        console.info($(val).parent().parent().parent().html());
        $(option).insertAfter($(val).parent().parent().parent());
        console.info(table.cache);
        var data = table.cache.datatable;
        table.cache.datatable.push({LAY_TABLE_INDEX:10,classy:"323423",code:"我爱你",elementName:"42342",createDate:null,creator:null,description:null,device:null,ebs:"234242",errorMsg:null,id:7,ifd:null,imei:null,modifiedBy:null,modifyDate:null,name:"1212",osid:null,pageIndex:null,pageSize:null,params:null,rowNum:0,vesion:null});
        form.render();
    }
    /**
     * 加载左侧树
     */
    function loadTree(){
        publicAjax (null,'infDisciplines/selectAllInfDisciplinesByTree',{name: $("#search").val()},null,null,function (r) {
            var jsondata = r.data;
            var json = {"id":-1,"name":"专业领域", open:true,parent:true};
            jsondata.push(json);
            zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, jsondata);
            var node = zTreeObj.getNodeByParam('id', -1);//获取id为1的点
            zTreeObj.selectNode(node);//选择点
            zTreeObj.setting.callback.onClick(null, zTreeObj.setting.treeId, node);//调用事件
        })
    }
    /**
     * 选中第一个节点
     * @param treeobj
     * @param id
     */
    function selectAppointNode(event, treeId, treeNode, msg) {
        if ($("#treeStructure_1_a").length > 0 && count ==1) {
            $("#treeStructure_1_a").click();
            count++;
        }
    }

    /**
     * 数据拦截器
     * @param treeId
     * @param parentNode
     * @param responseData
     */
    function formatedata(treeId,parentNode,responseData) {
        return formatTreeParseData(treeId,parentNode,responseData,function(parentNode,responseData){
            var jsonsdata = new Array();
            if(parentNode && parentNode.level==1){
                for(var i=0;i<responseData.data.length;i++){
                    delete responseData.data[i].parent;
                    jsonsdata.push(responseData.data[i]);
                }
            }else{
                jsonsdata = responseData.data;
            }
            return jsonsdata;
        });
    }

    /**
     * 点击触发
     * @param event
     * @param treeId
     * @param treeNode
     */
    function zTreeOnClick(event, treeId, treeNode) {
        if(treeNode){
            level = treeNode.level;
            treeNodeId = treeNode.id;
            selecNode = treeNode;
        }
        methodid = treeNode.id;
        loadTable();
    };
    /* *
     * @Author bxf
     * @Description 查询table数据
     * @Date 17:41 2019/8/30
     * @param null
     * @return
     */
    function searchTable(){
        var mycode = $("#code").val();
        var myname = $("#name").val();
        var myclassy = $("#classy").val();
        var myelementName = $("#elementName").val();
        loadTable(mycode,myname,myclassy,myelementName);
        $(".search_float_div").slideToggle();//关闭搜素div
    }
    /* *
     * @Author bxf
     * @Description 简单查询
     * @Date 17:46 2019/8/30
     * @param null
     * @return
     */
    function easysearch(){
        var mycode = '';
        var myname = '';
        var myclassy = '';
        var myelementName = $("#elementName1").val();
        loadTable(mycode,myname,myclassy,myelementName);
    }
    /* *
     * @Author bxf
     * @Description 重置查询
     * @Date 10:44 2019/10/29
     * @param null
     * @return
     */
    function resetSearchTable(){
        $("#code").val("");
        $("#name").val("");
        $("#classy").val("");
        $("#elementName").val("");
        searchTable();
    }
    /* *
     * @Author bxf
     * @Description 取消查询
     * @Date 17:44 2019/8/30
     * @param null
     * @return
     */
    function canclesearch(){
        $(".search_float_div").slideToggle();//关闭搜素div
    }

    function loadTable(mycode,myname,myclassy,myelementName){
        var width = $(".left-nav").css("width");
        $(".zTreeBackground.right").css("width",($(document).width()-350)+'px');//自适应表格处理
        $(".search_float_div").css("width",($(document).width()-350)+'px');//自适应搜索div

        var tableurl = publicUrl+'resmethods/selectListByPid';
        layui.use(['form','table','element'], function(){
            var element = layui.element;
            form = layui.form;
            table = layui.table;
            tableObj = table.render({
                elem: '#datatable',
                size: 'sm',
                toolbar: '#toolbar',
                even: true, //开启隔行背景
                height: 'full-70',
                headers: {"Authorization":getData("Authorization")},
                method: 'post',
                url: tableurl, //stationId='+window.parent.window.parentId,//8AE7DECA-8E41-4FAB-8B30-9FD1B0B7FA33,78A9E5D8-20FB-4436-BBE8-A25EAC38D056
                where:{
                    "params[level]":level,
                    "id":methodid,
                    "code":mycode,
                    "name":myname,
                    "myclassy":myclassy,
                    "elementName":myelementName
                },
                response: {
                    statusCode: 2000,
                },
                parseData: function(res){ //res 即为原始返回的数据
                    return formatTableParseData(res);
                },
                request: {
                    pageName: 'pageIndex' //页码的参数名称，默认：page
                    ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
                },
                done:function(){
                    //console.info($('.layui-table-body.layui-table-main .layui-table').html());
                    $('.layui-table-body.layui-table-main').on('scroll',function(){
                        // div 滚动了
                        var scroller = $(".layui-table-body.layui-table-main").scrollTop();
                        var divheight = $(".layui-table-body.layui-table-main").height();
                        var tableheight = $(".layui-table-body.layui-table-main .layui-table").height()
                        if ((scroller+divheight) >= tableheight) {
                            // 滚动到底部了
                            alert('滚动到底部了');
                        }
                    });
                },
                cols: [[
                    {
                        type:'checkbox',
                        width: "5px",
                    },
                    {
                        type: 'numbers',
                        title: '序号',
                        align: 'center',
                    }, {
                        field: 'code',
                        title: '编码',
                        width: "15%",
                        sort: true,
                        align: 'center',
                    },{
                        field: 'name',
                        title: '名称',
                        sort: true,
                        width: "14%",
                        align: 'center',
                        templet:function(r){
                            return '<span onclick="addtable(this)">添加</span>'+r.name;
                        }
                    }, {
                        field: 'classy',
                        title: '分类',
                        sort: true,
                        width: "12%",
                        align: 'center'
                    },{
                        field: 'elementName',
                        title: '构件名称',
                        sort: true,
                        width: "10%",
                        align: 'center'
                    },{
                        field: 'indsName',
                        title: '所属专业',
                        sort: true,
                        width: "10%",
                        align: 'center'
                    },{
                        field: 'description',
                        title: '描述',
                        width: "12%",
                        align: 'center',
                    }, {
                        field: 'ebs',
                        title: 'EBS编码',
                        width: "12%",
                        align: 'center',
                    }]],
                page: true
            });
            element.render();
        });

    }

    function cobyResmethods(){
        var iframeWin ;
        var nodes = zTreeObj.getSelectedNodes()[0];
        layer.open({
            type: 2,
            area: ["1050px" , "700px"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "工法添加",
            content: "./addexitresmethods.html",
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.addexitresmethods();//应用
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    delayLoad(function(){
                        layer.closeAll();
                    })
                }else{
                    return false;
                }
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.loadTable(nodes);//添加按钮
            }
        });
    }
    function uploadResmethods(){
        if(level!=2){
            layer.msg("请选择专业");
            return false;
        }
        var iframeWin ;
        var nodes = zTreeObj.getSelectedNodes()[0];
        layer.open({
            type: 2,
            area: ["500px" , "350px"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "工艺工法导入",
            content: "./uploadresmethod.html",
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: false,
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.getdisciplineId(nodes);//添加按钮
            }
        });
    }
    /**
     * @Author bxf
     * @Description 添加工艺工法
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function addResmethods(){
        if(level!=2){
            layer.msg("请选择专业");
            return false;
        }
        var iframeWin ;
        var nodes = zTreeObj.getSelectedNodes()[0];
        layer.open({
            type: 2,
            area: ["700px" , "600px"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "工法添加",
            content: "./addresmethods.html",
            btn: ['应用','确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.submit(level);//应用
                if(resultdata && resultdata.code==2000){
                    loadTable();
                }
                return false;
                //layer.closeAll();
            },
            btn2: function(index, layero){
                //按钮【按钮二】的回调
                var resultdata = iframeWin.contentWindow.submit(level);//保存
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    delayLoad(function(){
                        layer.closeAll();
                    })
                }else{
                    return false;
                }
            },
            btn3: function(index, layero){

                },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(1,nodes);//添加按钮
            }
        });
    }

    /**
     * @Author bxf
     * @Description 修改工艺工法页面
     * @Date 9:51 2019/7/18
     * @Param
     * @return
     **/
    function editResmethods(){
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请选择一项信息进行修改！");
            return false;
        }
        var data = obj.data[0]; //idTest 即为基础参数 id 对应的值
        data.pname = selecNode.name;
        var nodes = zTreeObj.getSelectedNodes()[0];
        var iframeWin ;
        layer.open({
            type: 2,
            area: ["700px" , "600px"],
            fix: false,
            //不固定
            maxmin: true,
            shade: 0.3,
            title: "工艺工法修改",
            content: "./addresmethods.html",
            btn: ['确定', '关闭'],
            // 弹层外区域关闭
            shadeClose: false,
            yes: function(index, layero) {
                var resultdata = iframeWin.contentWindow.updateInfdict(level);
                if(resultdata && resultdata.code==2000){
                    loadTable();
                    delayLoad(function(){
                        layer.closeAll();
                    })
                }else {
                    return false;
                }
            },
            cancel: function(index) {
                return true;
            },
            success: function(layero, index){
                iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.voluate(2,data);//添加按钮
            }
        });
    }

    /* *
     * @Author bxf
     * @Description 删除记录
     * @Date 11:19 2019/7/23
     * @param null
     * @return 
     */
    function  deleteResmethods() {
        //获取选中项
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length<1){
            layer.alert("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].id);
        }
        var nodes = zTreeObj.getSelectedNodes()[0];
        layui.use(['layer'],function(){
            var layer = layui.layer;
            layer.confirm('删除工艺工法会级联删除其它专业绑定绑定的该工艺工法，确定删除？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(){
                var delurl = 'resmethods/deleteResMethodsByIds';
                var data = {"ids":ids.join(","),"remark":1};//删除
                publicAjax (null,delurl,data,null,null,function (r) {
                    if(r.code==2000){
                        laysuccess("删除成功",null);
                        loadTable();
                    }else{
                        layerror("删除失败",null);
                    }
                });
            }, function(){
                layer.closeAll();

            });
        })
    }
    /* *
     * @Author bxf
     * @Description 移除记录
     * @Date 11:19 2019/7/23
     * @param null
     * @return
     */
    function  removeResmethods() {
        //获取选中项
        var obj = table.checkStatus('datatable');
        if(!obj || obj.data.length!=1){
            layer.alert("请至少选择一项信息！");
            return false;
        }
        var ids = new Array();
        for(var i=0;i<obj.data.length;i++){
            ids.push(obj.data[i].rdmid);
        }
        var nodes = zTreeObj.getSelectedNodes()[0];
        layui.use(['layer'],function(){
            var layer = layui.layer;
            layer.confirm('确定移除该工艺工法？', {
                btn: ['确定', '取消'] //可以无限个按钮
            }, function(){
                var delurl = 'resmethods/deleteResMethodsByIds';
                var data = {"ids":ids.join(","),"remark":2};//删除
                publicAjax (null,delurl,data,null,null,function (r) {
                    if(r.code==2000){
                        laysuccess("移除成功");
                        loadTable();
                    }else{
                        layerror("移动失败");
                    }
                    delayLoad(function(){
                        layer.closeAll();
                    })
                })
            }, function(){
                layer.closeAll();
            });
        })
    }

    /**
     * 打开选中指定节点
     * @param treeobj
     * @param id
     */
    function getAppointNode(treeobj,id){
        if(id){
            var node = treeobj.getNodeByParam("id",id);
            treeobj.selectNode(node,true);//指定选中ID的节点
            //treeobj.expandNode(node, true, false);//指定选中ID节点展开
        }
    }

    /**
     * 刷新指定节点
     */
    function refreshSelectNode(obj,id) {
        var node = obj.getNodeByParam("id",id);
        obj.reAsyncChildNodes(node,"refresh");
    }
    /**
     * 选中某个节点
     */
    function pointNode(obj,id){
        var nodeClick = obj.getNodeByParam("id", id);
        obj.selectNode(nodeClick);//选择点
        obj.setting.callback.onClick(null, id, nodeClick);//调用点击事件
    }


</script>
</html>